import React from 'react'
import { withRouter } from 'next/router'
import Link from 'next/link'
import axios from 'axios'

/**
 *  withRouter是Next.js框架的高级组件，用来处理路由用的
 * list: getInitialProps() 返回的数据
 * 在next中，只能在该方法中获取数据
 */
const Page3 = ({router, list}) => {
    return (
        <>
            <div>{router.query.name}, 欢迎你来到react的nextjs世界</div>
            <Link href="/">返回首页</Link>
        </>
    )
}

export default withRouter(Page3)

Page3.getInitialProps = async () => {
    const promise = new Promise((resolve) => {
        axios('https://www.easy-mock.com/mock/5cfcce489dc7c36bd6da2c99/xiaojiejie/getList').then(
                (res)=>{
                    console.log('远程数据结果：',res)
                    resolve(res.data.data)
                }
            )
    })

    return await promise
}
